package com.LeeCode;

import java.util.Arrays;

/**
 * 航班预订统计
 */

public class Code1109 {
    public static void main(String[] args) {
        int[][] bookings = {
                {1, 2, 10},
                {2, 3, 20},
                {2, 5, 25}
        };
        int n = 6;
        System.out.println(Arrays.toString(new Code1109().corpFlightBookings(bookings, n)));
    }

    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] diff = new int[n + 1];
        for (int[] booking : bookings) {
            int first = booking[0], last = booking[1], seats = booking[2];
            diff[first - 1] += seats;
            diff[last] -= seats;
        }
        int[] ans = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += diff[i];
            ans[i] = sum;
        }

        return ans;
    }
}
